#ifndef CONTOUR_EXTRACTOR_H_INCLUDED
#define CONTOUR_EXTRACTOR_H_INCLUDED

#include "types.h"
#include "image.h"
#include "contour.h"

/**\file contour_extractor.h
*  \brief Define the object that extract the contour of an image */

/** \class ContourExtractor
*   \brief This class define the object that extract the contour of an Image(Grey or Binary)
*/

class ContourExtractor{
    public:
        ///Get the contour of a Grey_Image
        ///Must be a unique connected shape
        ///\param image Pointer to Grey_Image
        ///\param label Label that identify the object of image
        ///\return Pointer to extracted Contour
        Contour* getContour(Grey_Image *image,unsigned int label,int neightbourhood);

        ///Get the contour of a Binary_Image
        ///Must be a unique connected shape
        ///\param image Pointer to Binary_Image
        ///\return Pointer to extracted Contour
        Contour* getContour(Binary_Image *image,int neightbourhood);
    private:

        ///Height of image contoured
        int height;
        ///Width of image contoured
        int width;
        ///Direction of previous to next pixel in chain-code
        int d_pc;
        ///Direction of previous to next pixel in chain-code
        int d_cn;
        ///First point of contour
        Position first;
        ///Current point of contour
        Position current;
        ///Next Point of contour
        Position next;
        ///Create relative positions for neighbours
        Position *neighbours;
        ///Neighbourhood, must be 8(EIGHTNEIGHBOURHOOD) ou 4((FOURNEIGHBOURHOOD))
        int neighbourhood;

        ///Function which invert the chain-code
        ///\param code The code which will be inverted
        int invertChainCode(int code);

        ///Find first point of contour
        ///\param image Pointer to Binary_Image
        ///\return The first point of contour
        Position findFirstPoint(Binary_Image *image);

        ///Find first point of contour
        ///\param image Pointer to Grey_Image
        ///\param label Label of shape
        ///\return The first point of contour
        Position findFirstPoint(Grey_Image *image,unsigned int label);

        ///Find next point of contour
        ///\param image Pointer to Binary_Image
        ///\return The next point of contour
        Position findNextPoint(Binary_Image *image);

        ///Find next point of contour
        ///\param image Pointer to Grey_Image
        ///\param label Label of shape
        ///\return The next point of contour
        Position findNextPoint(Grey_Image *image,unsigned int label);

        ///Get the contour of a Binary_Image
        ///Must be a unique connected shape
        ///\param image Pointer to Binary_Image
        ///\return Pointer to extracted Contour
        Contour* contourFollower(Binary_Image *image);

        ///Get the contour of a Grey_Image
        ///Must be a unique connected shape
        ///\param image Pointer to Grey_Image
        ///\param label Label that identify the object of image
        ///\return Pointer to extracted Contour
        Contour* contourFollower(Grey_Image *image,unsigned int label);

};

#endif // CONTOUR_EXTRACTOR_H_INCLUDED
